import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { Logger } from '../common/utils/Logger';

export default class EntryAbility extends UIAbility {
  onCreate(want, launchParam) {
    Logger.info('Ability onCreate')
  }

  onDestroy() {
    Logger.info('Ability onDestroy')
  }

  onWindowStageCreate(windowStage: window.WindowStage) {
    Logger.info('Ability onWindowStageCreate')

    windowStage.loadContent('pages/Index', (err, data) => {
      if (err.code) {
        Logger.error(`Failed to load the content. Cause: ${JSON.stringify(err) ?? ''} `)
        return;
      }
      Logger.info(`Succeeded in loading the content. Data: ${ JSON.stringify(data) ?? ''}`)
    });
  }

  onWindowStageDestroy() {
    Logger.info('Ability onWindowStageDestroy')
  }

  onForeground() {
    Logger.info('Ability onForeground')
  }

  onBackground() {
    Logger.info('Ability onBackground')
  }
}
